//
// Created by cy on 22-5-4.
//
#include "trance.hpp"
#include <csignal>

using namespace std;

static volatile int SIGNAL_INT = 0;

void signal_handler(int sig) {
    if (sig == SIGINT) {
        SIGNAL_INT = 1;
    }
    if (sig == SIGTERM) {
        SIGNAL_INT = 1;
    }
}

int main() {
    signal(SIGINT, signal_handler);
    signal(SIGTERM, signal_handler);

    auto trancePorter = TrancePorter::getInstance();
    trancePorter->open();
    while (!SIGNAL_INT) {
        auto data = trancePorter->read();
        if (data.isOk) {
            cout << "Pitch: " << data.pitch << "|Yaw: " << data.yaw << endl;
//            cout << "Yaw: " << data.yaw << endl;
        }
    }
    trancePorter->close();
}
